<template>
  <view>
    <hnav title="找房"></hnav>
    <Fit @success="sure"></Fit>
    <view>
      <uni-card
        v-for="(v, k) in houseinfo"
        :key="k"
        :title="v.title"
        :thumbnail="v.houseimg"
        :extra="'￥' + v.price + '.00/月'"
        padding="10px 0"
        @click="detail(v.houseCode)"
      >
        <image style="width: 100%" :src="v.houseimg"></image>
        <view class="tag">
          <uni-tag
            style="margin: 5px"
            :text="i == '' ? '暂无描述' : i"
            :type="tagcolor[j]"
            v-for="(i, j) in v.tags"
          />
        </view>
      </uni-card>
    </view>
  </view>
</template>

<script>
import Fit from "../../components/Fit";
export default {
  components: {
    Fit,
  },
  data() {
    return {
      houseinfo: [], //房屋详情列表
      tagcolor: ["success", "primary", "error", "warning", "royal"], //按钮状态
    };
  },
  methods: {
    async gethouse(fit = {}) {
      //请求房屋详情接口
      let areacode = uni.getStorageSync("cityinfo").code;
      let res = await this.$api.getHouse({ areaID: areacode, ...fit });
      if (res.data.code == 200) {
        console.log(res);
        this.houseinfo = res.data.msg;
      }
      console.log(this.houseinfo);
    },
    detail(v) {
      uni.navigateTo({ url: "/pages/detail/detail?code=" + v });
    },
    sure(v) {
      //确定筛选条件
      console.log(v);
      //更新筛选后的房源
      this.gethouse(v);
    },
  },
  mounted() {
    this.gethouse();
  },
};
</script>

<style>
.tag {
  display: flex;
  flex-wrap: wrap;
}
</style>
